<template>
<view>
	<view  class="item_xx" v-for="(item,index) in typeList" :key='index' @click="topage(item)">
		<image :src="item.img" mode=""></image>
		<view class="title">{{item.name}}</view>
	</view>
	<view class="item_xx" v-for="(item,index) in list" :key='index'>
		<view class="xx_l"  @click="change(item)">
			<view class="name">{{item.name}}</view>
			<view class="time">
				<view class="">
					{{item.createtime}}
				</view>
				<view :class="item.status==0?'red':'orange'">
					{{item.status==0?'未读':'已读'}}
				</view>
			</view>
		</view>
		<view class="btn_c" @click="del(item.id,index)">
			删除
		</view>
	</view>
	<view class="" style="height: 80px;width: 100%;"></view>
	<Tabbar :current="3"></Tabbar>
</view>
</template>

<script>
	import Tabbar from '@/components/tabbar.vue'
	import {xx ,GetBusinessclueList,GetMessageType} from '../../utils/api.js' 
	export default {
		data() {
			return {
				page:1,
				isNewRenderDone:true,
				list:[],
				acitve:1,
				companyList:[],
				typeList:[],
				page1:1,
				navH: uni.getStorageSync('navH'),
				navH1: uni.getStorageSync('navH1'),
				navH2: uni.getStorageSync('navH2'),
			}
		},
		onShow(){
			this.getList()
			this.getCList()
			this.getType()
		},
		components:{Tabbar},
		methods: {
			toDetail(item){
				uni.navigateTo({
					url:'/pages/companyDetail/companyDetail?identification='+item.identification
				})
			},
			getType(){
				GetMessageType().then(res=>{
					this.typeList = res.data
					console.log(res.data)
				})
			},
			getCList(){
				uni.showLoading({ mask:true,
					title:'正在加载'
				})
				GetBusinessclueList({page:this.page1}).then(res=>{
					if(this.page1==1){
						this.companyList= res.data.data
					}else{
						this.companyList.push(...res.data.data)
					}
					this.isNewRenderDone=true
					uni.hideLoading()
				})
			},
			getList(){
				uni.showLoading({ mask:true,
					title:'正在加载'
				})
				xx.GetMessagesList({page:this.page}).then(res=>{
					if(this.page==1){
						this.list= res.data.data
					}else{
						this.list.push(...res.data.data)
					}
					this.isNewRenderDone=true
					uni.hideLoading()
				})
			},
			change(item){
				xx.UpdateMessages({id:item.id,status:1})
				uni.navigateTo({
					url:item.url
				})
			},
			topage(item){
				uni.navigateTo({
					url:'/pages/xxList/xxDetail?type_id='+item.id 
				}) 
			}, 
			del(id,index){
				let that=this
				uni.showModal({
					title:'提示',
					content:'确定删除消息吗?',
				  success: function (res) {
						if (res.confirm) {
							xx.MessagesDel({id}).then(res=>{
								if(res.status==1){
									uni.showToast({
										title:'删除成功'
									})
									that.list.splice(index,1)
								}else{
									uni.showToast({
										title:res.msg,
										icon:'none'
									})
								}
							})
						} 
					}
				})
			}
		},
		onReachBottom() {
			// 加锁，避免在加载更多时用户频繁下拉导致的重复触发而渲染异常
			if(!this.isNewRenderDone) return;   
			this.isNewRenderDone = false
			// 模拟分页请求 (加载更多)
			if(this.active==1){
				this.page+=1
				this.getList()
			}else{
				this.page1 += 1
				this.getCList()
			}
			
		},
	}
</script>

<style scoped lang="scss">
.xx_l{
	width: calc(100% - 60px);
}
.btn_c{
	width: 50px;
	height: 28px;
	font-size: 14px;
	background-color: #ff9933;
	color: #fff;
	border-radius: 4px;
	line-height: 28px;
	text-align: center;
}
.item_xx{
	width: calc(100% - 28px);
	padding: 10px 14px;
	border-bottom: 1px solid #E5E5E5;
	display: flex;
	align-items: center;
	justify-content: space-between;
	&:active{
		background-color: rgba($color: #000000, $alpha: .1);
	}
	.time{
		font-size: 12px;
		color: #888;
		display: flex;
		justify-content: space-between;
	}
	.red{
		color: red;
	}
	.orange{
		color: #ff9933;
	}
	.name{
		position: relative;
		font-size: 14px;
		color: #333;
		margin-bottom: 6px;
	}
	.new::after{
		position: absolute;
		content:' ';
		width: 10px;
		font-size: 10px;
		top: 0px;
		left: -14px;
		border-radius: 5px;
		background: #red;
	}
	image{
		width: 36px;
		height: 36px;
		margin-right: 14px;
	}
	.title{
		font-size: 15px;
		width: calc(100% - 50px);
		position: relative;
		&::after{
			position: absolute;
			content: ' ';
			right: 0;
			top: 6px;
			width: 8px;
			height: 8px;
			border-top: 1px solid #888;
			border-right: 1px solid #888;
			transform: rotate(45deg);
		}
	}
}
.nav{
	width: 100%;
	position: fixed;
	top: 0;
	left: 0;
	background-color: rgba($color: #fff, $alpha: 1);
	z-index: 10;
	transition: all 0.5s;
}
.input_view{
	display: flex;
	width: 100%;
	justify-content: center;
	align-items: center;
	view{
		width: 70px;
		text-align: center;
		color: #888;
	}
	.active{
		font-size: 17px;
		font-weight: 800;
		color: #222;
		position: relative;
		&::after{
			position: absolute;
			content: ' ';
			bottom: -4px;
			width: 30px;
			height: 3px;
			border-radius: 1.5px;
			background-color: #ff7707;
			left: 20px;
		}
	}
}
	.box_item{
		width: calc(100% - 44px);
		margin: 10px 10px;
		background: #FFFFFF;
		box-shadow: 0px 2px 2px 2px rgba(191, 191, 191, 1);
		border-radius: 6px;
		display: flex;
		padding: 12px;
		position: relative;
		.image{
			width: 36px;
			height: 36px;
			margin-right: 8px;
		}
		.score1{
			position: absolute;
			right: 10px;
			font-size: 12px;
			color: #333;
		}
		.score{
			position: absolute;
			right: 16px;
			font-size: 22px;
			color: #f93;
			.sc{
				width: 24px;
				margin:0;
			}
		}
		.name1{
			width: calc(100% - 50px);
		}
		.name{
			font-size: 15px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 600;
			color: #333;
			line-height: 21px;
		}
		.info{
			font-size: 12px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #999999;
			line-height: 17px;
		}
	}
	.flex_c{
		display: flex;
		justify-content: space-between;
		align-items: center;
		.info{
			width: calc(100% - 40px);
		}
	}
	.chain_name{
		padding: 2px 4px;
		border-radius: 2px;
		font-size: 12px;
		color: #ff9933;
		background-color: rgba($color: #ff9933, $alpha: .1);
		display: inline-block;
		margin: 8px 6px 4px 0;
	}
	.chain_name1{
		padding: 2px 4px;
		margin: 8px 6px 4px 0;
		border-radius: 2px;
		font-size: 12px;
		color: #227aff;
		display: inline-block;
		background-color: rgba($color: #227aff, $alpha: .1);
	}
</style>
